import { request } from "umi";
import { AddDepartmentBean, UpdateDepartmentBean } from "./data";
import { ResponseData } from "@/utils/request";

// 查询部门
export async function queryDepartment() {
    return await request(`/department/view`);
}

//查询相邻一级部门
export async function getNearDepartment(department_id: string) {
    return await request('/department/view_near_dep', {
        params: {
            department_id: department_id
        }
    });
}

/**
 * 添加部门
 * @param data 
 */
export async function addDepartment(data: AddDepartmentBean): Promise<ResponseData<any>> {
    return await request('/department/add', {
        method: 'POST',
        data: data
    });
}

/**
 * 修改部门
 * @param data 
 */
export async function updateDepartment(data: UpdateDepartmentBean): Promise<ResponseData<any>> {
    return await request('/department/update', {
        method: 'POST',
        data: data
    });
}

/**
 * 删除部门
 * @param id 
 */
export async function deleteDepartment(id: string): Promise<ResponseData<any>> {
    return await request('/department/delete', {
        method: 'POST',
        data: {
            id: id
        }
    });
}